package cn.iocoder.yudao.module.worker.dal.mysql.category;

import java.util.*;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.worker.controller.app.category.vo.AppCategoryPageReqVO;
import cn.iocoder.yudao.module.worker.dal.dataobject.category.CategoryDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.worker.controller.admin.category.vo.*;

/**
 * 商品分类 Mapper
 *
 * @author Jerry
 */
@Mapper
public interface CategoryMapper extends BaseMapperX<CategoryDO> {

    default PageResult<CategoryDO> selectPage(CategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CategoryDO>()
                .eqIfPresent(CategoryDO::getParentId, reqVO.getParentId())
                .likeIfPresent(CategoryDO::getName, reqVO.getName())
                .eqIfPresent(CategoryDO::getThumb, reqVO.getThumb())
                .eqIfPresent(CategoryDO::getWeight, reqVO.getWeight())
                .eqIfPresent(CategoryDO::getBlindStatus, reqVO.getBlindStatus())
                .eqIfPresent(CategoryDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CategoryDO::getId));
    }

    default List<CategoryDO> selectList(CategoryPageReqVO listReqVO) {
        return selectList(new LambdaQueryWrapperX<CategoryDO>()
                .eqIfPresent(CategoryDO::getParentId, listReqVO.getParentId())
                .likeIfPresent(CategoryDO::getName, listReqVO.getName())
                .eqIfPresent(CategoryDO::getThumb, listReqVO.getThumb())
                .eqIfPresent(CategoryDO::getWeight, listReqVO.getWeight())
                .eqIfPresent(CategoryDO::getBlindStatus, listReqVO.getBlindStatus())
                .eqIfPresent(CategoryDO::getStatus, listReqVO.getStatus())
                .betweenIfPresent(CategoryDO::getCreateTime, listReqVO.getCreateTime())
                .orderByDesc(CategoryDO::getWeight));
    }

    default List<CategoryDO> selectList(AppCategoryPageReqVO reqVO) {
        if(reqVO.getIsOline() == null){
            reqVO.setIsOline(false);
        }
        return selectList(new LambdaQueryWrapperX<CategoryDO>()
                .eqIfPresent(CategoryDO::getParentId, reqVO.getParentId())
                .likeIfPresent(CategoryDO::getName, reqVO.getName())
                .eqIfPresent(CategoryDO::getThumb, reqVO.getThumb())
                .eqIfPresent(CategoryDO::getWeight, reqVO.getWeight())
                .eqIfPresent(CategoryDO::getBlindStatus, reqVO.getBlindStatus())
                .eq(reqVO.getIsOline() == false, CategoryDO::getIsOline, CommonStatusEnum.ENABLE.getStatus())
                .eq(CategoryDO::getStatus, true)
                .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CategoryDO::getWeight));
    }

    default PageResult<CategoryDO> selectPage(AppCategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CategoryDO>()
                .eqIfPresent(CategoryDO::getParentId, reqVO.getParentId())
                .likeIfPresent(CategoryDO::getName, reqVO.getName())
                .eqIfPresent(CategoryDO::getThumb, reqVO.getThumb())
                .eqIfPresent(CategoryDO::getWeight, reqVO.getWeight())
                .eqIfPresent(CategoryDO::getBlindStatus, reqVO.getBlindStatus())
                .eqIfPresent(CategoryDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CategoryDO::getId));
    }

}